package cn.woblog.android.common.utils.adapter;

import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * Created by ren on 2015/5/4 0004.
 */
public abstract class BaseFragmentPagerAdapter<T> extends FragmentPagerAdapter{
    protected final Context context;
    protected final  List<T> datas = new ArrayList<T>();
    protected final LayoutInflater inflater;

    public BaseFragmentPagerAdapter(Context context, FragmentManager fm) {
        super(fm);
        this.context= context;
        inflater = LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return datas.size();
    }

    public T getData(int position){
      return  datas.get(position);
    }

    /**
     * will clear the original data
     * @param data
     */
    public void setDatas(List<T> data) {
        if (data != null) {
            datas.clear();
            datas.addAll(data);
            notifyDataSetChanged();
        }
    }

    /**
     * add data
     * @param data
     */
    public void addDatas(List<T> data) {
        if (data != null&&data.size()>0) {
            datas.addAll(data);
            notifyDataSetChanged();
        }
    }

    public void addData(T data) {
        if (data != null) {
            datas.add(data);
            notifyDataSetChanged();
        }
    }

    public void clear() {
        datas.clear();
        notifyDataSetChanged();
    }

    /**
     * ��ȡ�ַ�
     * @param resId
     * @return
     */
    public String getString(int resId){
        return context.getResources().getString(resId);
    }
    public String getString(int resId,Object... args){
        return context.getResources().getString(resId,args);
    }



}
